from pypinyin import pinyin


def get_char__count():
    save_path = 'data/sort_中文.txt'
    sort_lines = open(save_path, encoding='utf8').readlines()
    char__count = {}
    chars = []
    for line in sort_lines:
        print(line)
        line = line.replace('\n', '')
        words = line.split('\t\t')
        if len(words) == 2:
            char = words[0]
            c = int(words[1])
            char__count[char] = c
            chars.append(char)
    return char__count, chars


def get_pinyin():
    path = 'data/字符-拼音.txt'
    fw = open(path, 'w', encoding='utf8')
    char__count, chars = get_char__count()
    for char in chars:
        p = pinyin(char)
        fw.write(f'{char}\t{p}\n')


get_pinyin()
